﻿using MaxStoreErp.Core.Exceptions;
using MaxStoreShop.Domain.Directories;
using MaxStoreShop.Logic.Services.Directories;
using MaxStoreShop.Logic.ServicesContracts.Directories;
using MaxStoreShop.Logic.Tests.FakeRepositories;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace MaxStoreShop.Logic.Tests
{
    [TestClass]
    public class StorageLocationServiceTests
    {
        [TestMethod]
        public void DeleteStorageLocationShouldNormal()
        {
            CreateInstance().DeleteStorageLocation(new StorageLocation {Id = 1});
        }

        [TestMethod]
        [ExpectedException(typeof (ErpRuntimeException))]
        public void DeleteStorageLocationShouldThrowErpRuntimeExceptionIfLocationIsNull()
        {
            CreateInstance().DeleteStorageLocation(null);
        }

        [TestMethod]
        public void SaveStorageLocationShouldNormal()
        {
            CreateInstance().SaveStorageLocation(new StorageLocation {Name = "Склад", Barcode = "123456"});
        }

        [TestMethod]
        [ExpectedException(typeof (ErpRuntimeException))]
        public void SaveStorageLocationShouldThrowErpRuntimeExceptionIfLocationIsnull()
        {
            CreateInstance().SaveStorageLocation(null);
        }

        [TestMethod]
        [ExpectedException(typeof(ErpRuntimeException))]
        public void SaveStorageLocationShouldThrowErpRuntimeExceptionIfNameIsEmpty()
        {
            CreateInstance().SaveStorageLocation(new StorageLocation {Barcode = "123456"});
        }

        [TestMethod]
        [ExpectedException(typeof(ErpRuntimeException))]
        public void SaveStorageLocationShouldThrowErpRuntimeExceptionIfBarcodeIsNull()
        {
            CreateInstance().SaveStorageLocation(new StorageLocation {Name = "Склад"});
        }

        static IStorageLocationService CreateInstance()
        {
            return new StorageLocationService(new StorageLocationRepositoryFake());
        }
    }
}
